/**
*处理一些基础数据
*公共部分
*/
var BasePack = function(){

	/** 点击菜单记录点击效果 */
	var recordClickEffect = function(){
		
		jQuery('.page-sidebar-menu li').live("click",function(){
			//alert(jQuery(this).attr('id'));
			//取消同级元素的效果
			//jQuery(this).siblings().removeClass('active');
			
			var menuid = jQuery(this).attr('id');
			var menuFlag = menuid.substr(0,menuid.indexOf("_"));
			
			if(menuFlag != 'oneli') 
				jQuery(this).siblings().removeClass('active');
			
			jQuery.cookie(menuFlag,menuid); 
			
		});
	}
	
	/** 回显点击效果 */
	var showClickEffect = function(){
		var oneMenu = jQuery.cookie('oneli');
		//alert(oneMenu);
		var twoMenu = jQuery.cookie('twoli');
		var threeMenu = jQuery.cookie('threeli');
		
		//alert(jQuery('#oneli_1').attr('id'));
		jQuery('#'+oneMenu).addClass('active');
		jQuery('#'+twoMenu).addClass('active');
		jQuery('#'+threeMenu).addClass('active');
	}
	
	
	/** 公开调用方法 **/
	var BasePublic = {
		/* 初始化菜单 */
		menuInit:function(){
			jQuery.ajax({
				url:'manage/power/ajaxShow',
				type:'POST',
				dataType:'json',
				success:function(data){
					//alert(JSON.stringify(data));
					
					var menu = "";
					//alert(JSON.stringify(data));
					//一级菜单
					jQuery.each(data,function(i,one){
						//alert(JSON.stringify(item));
						menu += '<li id="oneli_'+one.id+'">';
						menu += one.child != '' ? '<a href="javascript:;">' : '<a href="'+one.action+'">'; 
						menu += '<i class="'+one.clazz+'"></i>';
						menu += '<span class="title">'+one.name+'</span>';
						if(one.child != '')
							menu += '<span class="arrow "></span>';
						menu += '</a>';
						if(one.child != ''){
							menu += '<ul class="sub-menu">';
							//二级菜单
							jQuery.each(one.child,function(i,two){
								menu += '<li id="twoli_'+two.id+'">';
								menu += two.child != '' ? '<a href="javascript:;">' : '<a href="'+two.action+'">'; 
								menu += '<i class="'+two.clazz+'"></i>'+two.name;
								if(two.child != '')
									menu += '<span class="arrow"></span>';
								menu += '</a>';
								//alert(i);
								if(two.child != ""){
									//alert(two.child);
									menu += '<ul class="sub-menu">';
									//三级菜单
									jQuery.each(two.child,function(n,three){
										menu += '<li id="threeli_'+three.id+'">';
										menu += '<a href="'+three.action+'"><i class="'+three.clazz+'"></i>'+three.name+'</a>';
										menu += '</li>';
									});
									menu += '</ul>';
								}
								menu += '</li>';
							});
							menu += '</ul>';
						}
						menu += '</li>';
						
					});
					
					jQuery('.page-sidebar-menu').append(menu);
					//alert(menu);
					
					//回显点击效果
					showClickEffect();
				},
				error:function(data){
					alert(JSON.stringify(data));
				}
			});
			
			//记录点击效果
			recordClickEffect();
			
		},
		//初始化模板
		initTheme:function(){
			//初始化模板颜色
			var theme_color = jQuery.cookie('theme_color');
			jQuery('#theme_color').attr("href", Layout.getLayoutCssPath() + 'themes/' + (theme_color ? theme_color : 'default') + ".css");
			
			//初始化模板样式
            var theme_style = jQuery.cookie('theme_style');
            jQuery('#style_components').attr("href", Metronic.getGlobalCssPath() + (theme_style ? theme_style : 'components') + ".css");
            
            
			
		}
	};
	
	return BasePublic;
	
}();	